<template>
  <div>
	  <el-tabs v-model="activeName" @tab-click="handleClick">
	      <el-tab-pane label="周一" name="first">周一</el-tab-pane>
	      <el-tab-pane label="周二" name="second">周二</el-tab-pane>
	      <el-tab-pane label="周三" name="third">周三</el-tab-pane>
	      <el-tab-pane label="周四" name="fourth">周四</el-tab-pane>
		  <el-tab-pane label="周五" name="five">周二</el-tab-pane>
		  <el-tab-pane label="周六" name="six">周三</el-tab-pane>
		  <el-tab-pane label="周七" name="seven">周四</el-tab-pane>
	    </el-tabs>
    <el-row :gutter="10">
      <el-col :span="5"><el-input v-model="search.name" placeholder="请输入要查询的菜名"></el-input></el-col>
      <el-col :span="19">
        <el-button type="primary" icon="el-icon-search" plain @click="searchData()">搜索</el-button>
      <!--  <el-button type="primary" icon="el-icon-circle-plus-outline" plain @click="add()">添加菜色</el-button> -->
  
      </el-col>
    </el-row>
    <el-table
         :data="result.tableData"
        style="width: 100%"
        :row-class-name="tableRowClassName">
		
		<!-- <el-table-column
		  prop="id"
		  label="序号"
		  width="180">
		</el-table-column> -->
		
		<el-table-column
		  prop="foodDate"
		  label="日期"
		  width="180">
		</el-table-column>
		<el-table-column
		  prop="foodTime"
		  label="餐次"
		  width="180">
		</el-table-column>
        <el-table-column
          prop="foodType"
          label="类别"
          width="180">
        </el-table-column>
        <el-table-column
          prop="name"
          label="名称"
          width="180">
        </el-table-column>
        <el-table-column
          prop="foodPrice"
          label="价格"
		  width="180">
        </el-table-column>
		<el-table-column
		  prop="muslimFood"
		  label="是否清真"
		  width="180">
        <template slot-scope="scope">
          <span v-if="scope.row.muslimFood === '1'">清真</span>
          <span v-else>不清真</span>
        </template>

		 <!-- </el-table-column>
		      <el-table-column label="操作"width="220px" >           
 <template slot-scope="scope">
		 	          <template >
						    <el-button type="warning"
						   size="mini"
						  icon="el-icon-edit" 
						 @click="edit(scope.row.id)">修改</el-button>
						  
					
		 	            <el-button
		 	              size="mini"
		 	              type="danger"
						  icon="el-icon-delete-solid" 
		 	              @click="del(scope.row.id)">删除</el-button>
		 
		 	          </template>
		 	        </template>
			
			</el-table-column> -->

      </el-table>
    <el-pagination
      style="margin-top:20px;"
      background
      layout="prev, pager, next"
      :page-count="result.pages"
      :current-page.sync="query.pageNo"
      :page-size="query.pageSize"
      @current-change="getData()">
    </el-pagination>
	<el-dialog :title="title" :visible.sync="show" :close-on-click-modal="false" width="500px">
		<foodEdit v-if="show" :show.sync="show" @getData="getData()" :editid="editid">
		</foodEdit>
	</el-dialog>
   
  </div>
</template>

<script>
import foodEdit from '@/views/food/edit' 
export default {
  name: 'food',
  components:{
	  foodEdit
  },
  data() {
    return {
	showNum: 0,
	editid: null,
      search: {
        name: ''
      },
      query: {
        name: '',
        pageNo: 1,
        pageSize: 8
      },
      result:{
        tableData: [],
        pages: 0
      },
      show: false,
      selectedrow: [],
      title: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      this.axios.get('/food/list',response => {
        this.result.tableData = response.obj.records
        this.result.pages = response.obj.pages
		console.log(this.result.tableData)
      },this.query)
    },
    searchData() {
      this.query.name = this.search.name
      this.query.pageNo = 1
      this.getData()
    },
    edit(id) {
      this.title = '修改'
      this.editid = id
	  this.showNum++;
      this.show = true
    },
    add(){
      this.title = '添加'
      this.editid = null
	  this.showNum++;
      this.show = true
    },
    del(id) {
      this.axios.del('/food/del',response => {
        this.getData()
      },{ id: id })
    },
    handleSelectionChange(val) {
      // val参数为所有选中行的数据
      this.selectedrow = val
    },
    batchdel() {
      if(this.selectedrow.length === 0) {
        this.$message('没有任何被选中的数据');
      } else {
        const ids = []
        for(let i = 0; i < this.selectedrow.length; i++) {
          ids.push(this.selectedrow[i].id)
        }
        this.axios.del('/food/batchdel',response => {
          this.getData()
        },{ ids: ids })
      }
    },
    handleBack(id) {
      this.axios.del('/food/back',response => {
        this.getData()
      }, { id: id }, 'back')
    },
    gorole(id) {
      this.$router.push({
        path: '/food',
        query:{
          id: id
        }
      })
    },
	   open() {
	     this.$prompt('请输入处理内容', '提示', {
	       confirmButtonText: '确定',
	       cancelButtonText: '取消',
	     }).then(({ value }) => {
	       this.$message({
	         type: 'success',
	         message: '处理内容是: ' + value
	       });
	     }).catch(() => {
	       this.$message({
	         type: 'info',
	         message: '取消输入'
	       });       
	     });
		 }
  }
}
</script>
<style scoped>
	.el-table .warning-row {
	    background: oldlace;
	  }
	
	  .el-table .success-row {
	    background: #f0f9eb;
	  }
</style>